package com.zjh.elktest;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

public class BulkReq {
    public static void main(String[] args) throws IOException {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("10.50.3.20", 9200, "http")));

        BulkRequest bulkRequest=new BulkRequest();
        bulkRequest.timeout("1s");

        //可通过for循环添加多个
        bulkRequest.add(
                new IndexRequest("javatestindex")
                .id("1")
                .source("JSON")
        );

        BulkResponse response = client.bulk(bulkRequest, RequestOptions.DEFAULT);
        System.out.println("是否失败："+response.hasFailures());

    }
}
